home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / real2fs < prev    next >
Text File  |  1995-03-31  |  2KB  |  55 lines

  1. Newsgroups: comp.sys.hp48
  2. Subject: R\->FS (Real to Fraction String) (*SHORT* utility)
  3. Followup-To: 
  4. Distribution: world
  5. Organization: State University of New York @ Buffalo
  6. Keywords: 
  7.  
  8. IHMO, this isn't something that warents posting to c.src.hp48.
  9. I'll manually dump it in the archives at seq and wuarchive.
  10.  
  11. For a project I'm working on, I needed a routine to display a real with the
  12. fraction part replaced by on of the fraction characters (188 thru 190,
  13. decimal, in the ISO LAtin1 Character Set).  As I often write these short
  14. utilities in userlang first, to make sure they work, I came up with the
  15. following.  I thought some might find it useful themselves.  
  16.  
  17. The syntax looks like:
  18.  
  19. ( 1:Real ) ==> ( 1:String )
  20.  
  21. Where Real is any real, and the output string has the format:
  22. "iiiiiiiiiif", where the i's are the integer part, and the f is the
  23. fraction character (space, one-quarter, one-half, or three-quarters).
  24.  
  25. As my project will only need to use this on values less than one thousand,
  26. I've made no attempt to deal with values whose absolute value is greater
  27. than or equal to 1e10.
  28.  
  29. Also, if the value passed is negative, a minus sign will prepend the format
  30. as described above.  Again, all my values are >0, so I didn't bother.
  31. Adding support for that would be trivial.
  32.  
  33. Here is the file:
  34.  
  35. %%HP: T(3)A(R)F(.);
  36. @ R\->FS
  37. @ Takes real in (-1e10,1e10) and returns string representing that number
  38. @ with the fracion part replaced by either a sapce or the ISO-Latin1
  39. @ fraction character closest to the original fractional part.
  40. @ Posted by James H. Cloos, Jr.  Use at will.
  41. @ cloos@acsu.buffalo.edu   ;;  cloos@ub.UUCP
  42. \<< RCLF STD SWAP 4 * 0 RND 4 / DUP IP SWAP FP
  43.   IF DUP
  44.   THEN 4 * ABS 187 + CHR
  45.   ELSE DROP " "
  46.   END + SWAP STOF
  47. \>>
  48.  
  49.  
  50. -JimC
  51. --
  52. James H. Cloos, Jr.        Phone:  +1 716 673-1250
  53. cloos@ACSU.Buffalo.EDU        Snail:  PersonalZipCode:  14048-0772, USA
  54. cloos@ub.UUCP            Note:    Phone & Snail to change soon!
  55.